<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<h1>Test for smart delete backward on double click selected word.</h1>
<p>Please tun this test with layout test runner</p>
<p>To run it manually, double click on 'bar' and hit backspace.  You should see 'foo baz'.</p>
<div id="includeSpace" contenteditable="true">foo b<span id="target">a</span>r baz</div>
<div id="notIncludeSpace" contenteditable="true">foo b<span id="target">a</span>r baz</div>
<div id="log"></div>
<script>
function testIt(sampleId, expectedString, expectedOffset) {
    if (!window.eventSender || !window.internals || window.testRunner)
      return;
    var selection = window.getSelection();
    var sample = document.getElementById(sampleId);
    var target = sample.querySelector('#target');
    internals.settings.setSelectTrailingWhitespaceEnabled(sampleId == 'includeSpace');
    eventSender.mouseMoveTo(target.offsetLeft, target.offsetTop);
    eventSender.mouseDown();
    eventSender.mouseUp();
    eventSender.mouseDown();
    eventSender.mouseUp();
    testRunner.execCommand('DeleteBackward');
    assert_equals(sample.innerText, expectedString, sampleId);
    assert_true(selection.isCollapsed);
    assert_equals(selection.focusNode,  sample.firstChild, sampleId + ' focusNode');
    assert_equals(selection.focusOffset, expectedOffset,  sample.firstChild, sampleId + ' focusOffset');
}
test(testIt.bind(this, 'includeSpace', 'foo baz', 4), 'includeSpace');
test(testIt.bind(this, 'notIncludeSpace', 'foo\u00A0baz', 3), 'notIncludeSpace');
</script>
